import Axios from './resetAxios'
import api from './apiPath'

// ``````````{ login，index }相关API```````````````

// 获取公钥fun
export function getRsaPublicKeyFun (params) {
  return new Promise((resolve, reject) => {
    Axios.GET(api.getRsaPublicKey, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 登录fun
export function loginFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.login, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 资源管理---查询所有菜单tree
export function selectMenuTreeByIdFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.selectMenuTreeById, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// ```````````````````````系统管理API```````````````````````````

// 资源管理---查询所有资源tree（包括菜单，不包括功能）
export function selectResourceTreeFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.selectResourceTree, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 根据resourceId查询下一级子节点
export function selectChildByResourceIdFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.selectChildByResourceId, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 资源管理---新增
export function resourceMng_insertFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.resourceMng_insert, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 资源管理---编辑
export function resourceMng_updateFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.resourceMng_update, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 资源管理---删除
export function resourceMng_deleteFun (params) {
  return new Promise((resolve, reject) => {
    Axios.GET(api.resourceMng_delete, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 角色管理---查询所有启用资源tree（包括菜单和功能）
export function selectEnableResourceTreeFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.selectEnableResourceTree, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 角色管理---根据角色ID查询所有角色下启用的资源tree（包括菜单和功能）
export function selectEnableResourceTreeByRoleIdFun (params) {
  return new Promise((resolve, reject) => {
    Axios.GET(api.selectEnableResourceTreeByRoleId, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 角色管理---查询
export function roleMng_selectFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.roleMng_select, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 角色管理---新增
export function roleMng_insertFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.roleMng_insert, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 角色管理---编辑
export function roleMng_updateFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.roleMng_update, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 角色管理---删除
export function roleMng_deleteFun (params) {
  return new Promise((resolve, reject) => {
    Axios.GET(api.roleMng_delete, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 查询所有启用的角色
export function selectAllEnableRolesFun (params) {
  return new Promise((resolve, reject) => {
    Axios.GET(api.selectAllEnableRoles, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 用户管理---新增
export function userMng_insertFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.userMng_insert, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 用户管理---查询
export function userMng_selectFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.userMng_select, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 用户管理---编辑
export function userMng_updateFun (params) {
  return new Promise((resolve, reject) => {
    Axios.POST(api.userMng_update, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 用户管理---删除
export function userMng_deleteFun (params) {
  return new Promise((resolve, reject) => {
    Axios.GET(api.userMng_delete, params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}
